<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'carmanager.jsp' starting page</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/1.3.4/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/wu.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/icon.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.3.4/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.3.4/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
$(function(){
	$("#carorders").submit(function(){
			var carinfoz=$("input[name='carinfoz']").val();
			var otheruser=$("input[name='otheruser']").val();
			var destination=$("input[name='destination']").val();
			var driver=$("input[name='driver']").val();
			var starttime=$("input[name='starttime']").val();
			var endtime=$("input[name='endtime']").val();
			var length=$("input[name='length']").val();
			var content=$("input[name='content']").val();
			var nextuser=$("input[name='nextuser']").val();
			if(carinfoz==""||carinfoz==null ){
				alert('请选择车辆车牌号');
				return false;
			}
			if(otheruser==""||otheruser==null){
				alert('请填写随行人员，');
				return false;
				}else if(otheruser.length>=20){
					alert('超出填写范围');
					return false;
				}
			
  			
				if(destination==""||destination==null){
					alert('请填写目的地');
					return false;
				}else if(destination.length>=15){
					alert('超出填写范围');
					return false;
				}
			if(driver==""||driver==null){
					alert('请填写司机');
					return false;
				}else if(driver.length>=10){
					alert('超出填写范围');
					return false;
				}
			if(starttime==""||starttime==null){
				alert('请填写开始时间');
				return false;
			}
				if(endtime==""||endtime==null){
				alert('请填写结束时间');
				return false;
			}
			if(length==""||length==null ){
				alert('请填写行驶里程');
				return false;
				}else if(length.length>=6){
					alert('超出填写范围');
					return false;
				}
			
			if(content==""||content==null){
					alert('请填写申请事由');
					return false;
				}else if(content.length>=50){
					alert('超出填写范围');
					return false;
				}
			if(nextuser==""||nextuser==null){
				alert('请选着审批人');
				return false;
			}
				return true;	
	});
	});




$(function(){
	var msg=$('#msg').val();
	if(msg!=""){
		$.messager.show({
			title:'info',
			msg:msg
		});
	}
	$('#msg').val("");
});

$(function(){
		$('#carinfos').form({   
		    url:'${pageContext.request.contextPath}/car?op=updcarinfo',   
		    onSubmit: function(){     
		    },   
		    success: function(data){   
 						var data = eval('(' + data + ')');  
 						if (data.success){   
     					   $('#cardoor').window('close');  
     					   $("#cars").datagrid('reload');
     				 }
		    }   
		});
		$('#carinfadd').form({   
		    url:'${pageContext.request.contextPath}/car?op=addcarinfo',   
		    onSubmit: function(){     
		    },   
		    success: function(data){   
 						var data = eval('(' + data + ')');  
 						if (data.success){   
     					   $('#addcardoor').window('close');  
     					   $("#cars").datagrid('reload');
     				 }
		    }   
		});      
	});
$(function(){
		var role = ${sys_user.role.id};
		if(role!=1&&role!=2&&role!=4){
			$('#tipinfo').text("对不起！您尚未拥有该权限");
			return;
		}
		$("#cars").datagrid({   
		    url:'${pageContext.request.contextPath}/car?op=carinfo',   
		    columns:[[   
		        {field:'id',title:'编号',checkbox:true},
		        {field:'carno',title:'车牌号',width:100},  
		        {field:'carkind',title:'车型',width:100},   
		        {field:'tip',title:'备注',width:100},
		    ]],
		    fitColumns : true,
			autoRowHeight : false, 
			striped : true,
			loadMsg : '请等待...',
			pagination : true,
			nowrap : true,
			rownumbers : true,
			fit : true,
				toolbar : [{
			 	text:'修改',
				iconCls : 'icon-edit',
				handler : function() {
					var obj = $("#cars").datagrid("getSelected");
					$("#id").val(obj.id);
					$("form").removeAttr("style");
					$("#cardoor").window({   
					    width:600,   
					    height:400,   
					    modal:true ,
					    title:'修改车信息',
					    iconCls:'icon-edit'
					});
					$("#carinfos").form('load',{
						carno:obj.carno,
						carkind:obj.carkind,
						tip:obj.tip,
					});
				}
				}, '-', {
				text:'添加',
				iconCls : 'icon-add',
				handler : function() {
					$("#carinfadd").removeAttr("style");
					$("#addcardoor").window({   
					    width:600,   
					    height:400,   
					    modal:true ,
					    title:'添加用车信息',
					    iconCls:'icon-add'
					});
				}
				}, '-', {
					text:'删除',
					iconCls : 'icon-remove',
					handler : function() {
					 	var obj = $("#cars").datagrid("getSelected");
						var str=confirm("确认删除客户信息?");
						if(str==true){
							location.href='${pageContext.request.contextPath}/car?op=delcarinfo&id='+obj.id;
						}
				} 
			}]	
		});
		
		
});
$(function(){
	$('#cont').combotree({   
	    url: '${pageContext.request.contextPath}/shedule?op=showcombooTree',   
	    onBeforeExpand:function(node,param){
	    	$('#cont').combotree("tree").tree("options").url='${pageContext.request.contextPath}/shedule?op=showcombooTree';
		},
	       cascadeCheck:false,
	});

	$("#carinfoz").combobox({
			url:'${pageContext.request.contextPath}/car?op=carinfo',
			valueField:'id',
			textField:'carno',
			panelHeight:'auto'
		});
		$("#department").combotree({
			url: '${pageContext.request.contextPath}/shedule?op=showcombooTree',
			 cascadeCheck:false,
		});
		$('#carorders').form({   
		    url:'${pageContext.request.contextPath}/car?op=addcarorder',   
		    onSubmit: function(){
		         
		    },   
		    success: function(data){   
 						var data = eval('(' + data + ')');  
 						if (data.success){
 								alert('申请成功，等待审批');
 						}
 			} 
});
});
$(function(){
	$('#button').click(function(){
		location.href='${pageContext.request.contextPath}/carmanager.jsp';
	})
});
$(function(){
				var deptid = $("#deptid").val();
				
				$("#pp").combobox({
				url:'${pageContext.request.contextPath}/user?op=Leader',
				valueField:'id',
				textField:'realname',
				panelHeight:'auto'
				});
				$("#pb").combobox({
				url:'${pageContext.request.contextPath}/dept?op=showRealName&id='+deptid,
				valueField:'id',
				textField:'realname',
				panelHeight:'auto'
				});


	$('#nextuser').combobox({
		url:'${pageContext.request.contextPath}/user?op=deptrole&uid='+$("#uid").val(),
		valueField:'id',
		textField:'realname',
		panelHeight:'auto'
	});

});
	
</script>
</head>
  
  <body class="easyui-layout">
  <div><input type="hidden" id="msg" value="${e}"></div>
    <div data-options="region:'center'" style="padding:5px;background:#eee;" id="tt" class="easyui-tabs" >  
    <div title="用车申请" style="padding:20px;text-align:left;line-height:25px">
    <form method="post" id="carorders">
    <div style="float: left;padding-right:10px">
    	<div>
    		<input type="hidden" id="uid" name="uid" value="${sys_user.id }">
        	<label for="carinfoz">车辆编号:</label>&nbsp;&nbsp;
			<input class="easyui-validatebox" type="text" id="carinfoz" name="carinfoz" ></input>
        </div>  
        <div>
        	<label for="otheruser">随行人员:</label>&nbsp;&nbsp;
			<input class="easyui-validatebox" type="text" name="otheruser" ></input>
        </div>
        <div>
        	<label for="destination">目的地 :</label>&nbsp;&nbsp;&nbsp;&nbsp;
			<input class="easyui-validatebox" type="text" name="destination" ></input>
        </div>
        <div>
        	<label for="driver">司机 :</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input class="easyui-validatebox" type="text" name="driver" ></input>
        </div>
        </div>
        <div>
        <div>
        	<label for="usercar">用车人 :</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        	<input type="hidden" name="usercar" value="${sys_user.id }">
        	${sys_user.realname }
        </div>
        <div>
        	<label for="starttime">时间 :</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input class="easyui-validatebox" type="text" name="starttime" ></input>-
			<input class="easyui-validatebox" type="text" name="endtime" ></input>
        </div>
        <div>
        	<label for="department">用车部门:</label>&nbsp;&nbsp;
			<input class="easyui-validatebox" type="text" id="department" name="department" value="${sys_user.department.id }" readonly="readonly"></input>
        </div>
        <div>
        	<label for="length">申请里程:</label>&nbsp;&nbsp;
			<input class="easyui-validatebox" type="text" name="length" ></input>（公里）
        </div>
		</div>
		
		<div>
			<label for="content">用车事由:</label>&nbsp;&nbsp;
			<textarea rows="8" cols="60" name="content"></textarea>
		</div>
		<hr/><br/>
		<div style="margin: auto;width: 800px;height: 40px; margin-top:15px;">
			<table style="margin-left: 50px">
				<tr>
					<td style="width: 150px">下一步审批人:</td>
					<td style="width: 150px">
					<c:if test="${sys_user.role.id==5 }">
						<input type="text" id="pb" name="nextuser"/>
						<input type="hidden" id="deptid" value="${sys_user.department.id }"/>
						
					</c:if>
					<c:if test="${sys_user.role.id==3 }">
						<input type="text" id="pp" name="nextuser"/>
					</c:if>
						
					</td>
					<td style="width: 200px"></td>
					<td style="width: 100px">
						<input type="submit" value="确定">
					</td>
					<td style="width: 100px">
						<input type="submit" value="取消">
					</td>
				</tr>
			</table>
		</div>

		</form>
    </div>
 
 
    <div title="用车管理" style="overflow:auto;padding:20px;">  
        <table id="cars"></table>
        <!-- 修改 -->
        <div id="cardoor" style="text-align:left;line-height:40px;padding-top:20px">
        	<form style="display: none;" method="post" id="carinfos">
        			<div><input name="id" id="id" type="hidden"></div>
					 <div>
			            <label for="carno">车牌号:</label>&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="text" name="carno" ></input>
			        </div>
			        <div>
			            <label for="carkind">车型:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="text" name="carkind"></input>
			        </div>
			        <div>
			            <label for="tip">备注:</label>&nbsp;&nbsp;&nbsp;&nbsp;
			            <textarea rows="10" cols="60" name="tip"></textarea>
			        </div>
			        <div style="text-align:center; ">
						<input type="submit" value="提交" />
					</div>
        	</form>       
        </div>
        <span id='tipinfo'></span>
        <!-- 添加 -->
        <div id="addcardoor" style="text-align:left;line-height:40px;padding-top:20px">
        	<form  method="post" id="carinfadd" style="display: none;">
					 <div>
			            <label for="carnos">车牌号:</label>&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="text" name="carnos" ></input>
			        </div>
			        <div>
			            <label for="carkinds">车型:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="text" name="carkinds"></input>
			        </div>
			        <div>
			            <label for="tips">备注:</label>&nbsp;&nbsp;&nbsp;&nbsp;
			            <textarea rows="10" cols="60" name="tips"></textarea>
			        </div>
			        <div style="text-align:center; ">
						<input type="submit" value="提交" />
					</div>
        	</form>       
        </div>
    </div> 
</div>     
<div id="dd"></div>

</body>
</html>
